package all_in_one;

import java.util.ArrayList;
import java.util.concurrent.Semaphore;

public class CigarettePlace {
	private Aggy m_aggy =  new Aggy(this);
	private ISmoker m_toby = new Toby(this);
	private ISmoker m_pappy = new Pappy(this);
	private ISmoker m_manny = new Manny(this);
	
	private Paper m_paper = new Paper();
	private Tobacco m_tobacco = new Tobacco();
	private Match m_match = new Match();
	
	private Count m_counter = new Count();
	private ArrayList<Semaphore> m_sema_array = new ArrayList<Semaphore>();
	
	private Delta m_delta1 = new Delta(this, 0);
	private Delta m_delta2 = new Delta(this, 1);
	private Delta m_delta3 = new Delta(this, 3);
	
	private Constraint_Toby ct = new Constraint_Toby(this);
	private Constraint_Pappy pt = new Constraint_Pappy(this);
	private Constraint_Manny mt = new Constraint_Manny(this);
	
	private Grabbers grabbers = new Grabbers(this);
	
	public void Initialise() {
		// Create array of semas
		for (int i=0; i<6; ++i) {
			m_sema_array.add(new Semaphore(1));
			m_sema_array.get(i).drainPermits();
			}
		
		pt.start();
		ct.start();
		mt.start();
		
		m_delta1.start();
		m_delta2.start();
		m_delta3.start();
		
		((Thread) m_toby).start();
		((Thread) m_pappy).start();
		((Thread) m_manny).start();
		
		grabbers.run();
		
		m_aggy.start();
		
		
	}
	public void run() {
		
	}
	public ArrayList<Semaphore> GetSemaphoreArray() {return m_sema_array;}
	public Semaphore GetPaperSemaphore() 			{ return m_paper.GetSemaphore(); }
	public Semaphore GetMatchSemaphore() 			{ return m_match.GetSemaphore(); }
	public Semaphore GetTobaccoSemaphore() 			{ return m_tobacco.GetSemaphore(); }
	public Paper GetPaper()					{ return m_paper; }
	public Tobacco GetTobacco()				{ return m_tobacco; }
	public Match GetMatch()					{ return m_match; }
	public Count GetCounter() 				{ return m_counter; }
	public Semaphore GetAggySemaphore() 	{ return m_aggy.GetSemaphore(); }
	public ISmoker GetToby() 				{ return m_toby; }
	public ISmoker GetPappy() 				{ return m_pappy; }
	public ISmoker GetManny() 				{ return m_manny; }
	
}
